package com.mbc.controller;


import com.github.pagehelper.PageInfo;
import com.mbc.comment.Result;
import com.mbc.service.PopularScienceService;
import com.mbc.vo.PopularScienceTweetInfoVO;
import com.mbc.vo.PopularScienceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * <p>
 * 科普表 前端控制器
 * </p>
 *
 * @author suimeng
 * @since 2024-04-16
 */
@RestController
@RequestMapping("/popularScience")
@Api(tags = "科普百科接口")
@CrossOrigin
public class PopularScienceController {

    @Autowired
    private PopularScienceService popularScienceService;

    /**
     * 查询科普推文
     *
     * @return {@link Result}<{@link ArrayList}<{@link PopularScienceVO}>>
     */
    @GetMapping("/Tweets")
    @ApiOperation("查询科普小推文")
    public Result<PageInfo<PopularScienceVO>> getPopularScienceTweets(@RequestParam(defaultValue = "1") Integer page,
                                                                      @RequestParam(defaultValue = "10") Integer size) {
        PageInfo<PopularScienceVO> list = popularScienceService.getPopularScienceTweets(page, size);
        return Result.success(list);
    }

    /**
     * 查询科普推文信息
     *
     * @param title 标题
     * @return {@link Result}<{@link PopularScienceTweetInfoVO}>
     */
    @GetMapping("/TweetInfo")
    @ApiOperation("根据标题查询科普推文内容")
    public Result<PopularScienceTweetInfoVO> getPopularScienceTweetInfo(@RequestParam String title) {
        PopularScienceTweetInfoVO popularScienceTweetInfoVO = popularScienceService.getPopularScienceTweetInfo(title);
        return Result.success(popularScienceTweetInfoVO);
    }
}